<!DOCTYPE HTML>
<html>
<head>
    <title>Todo</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
    <script src="/editor/js/moveBall.js"></script>
</head>
<body  style="padding: 0;width: 100%;height: 100%">
<div id="outImg">
    <img id="imgId" src="" alt="" onclick="smallImg()">
</div>
<div style="padding-bottom:5px;">
    <span>用户昵称：</span><input class="mini-textbox" type="text" id="nickName"/>
    <span>用户id：</span><input class="mini-textbox" type="text" id="userOId"/>
    <a class="mini-button" iconCls="icon-search" onclick="search()">查找</a>
</div>
<div style="width:99%;">
    <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
                    <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>
                </td>
            </tr>
        </table>
    </div>
</div>
<div id="datagrid1" class="mini-datagrid" style="width:99%;height: 82%;"
     url="/getdata/admin" idField="id" allowResize="true"
     sizeList="[20,30,50,100]" pageSize="30"
>
    <div property="columns">
        <div type="checkcolumn" ></div>
        <div field="objectId" width="80" headerAlign="center" allowSort="true" >objectId</div>
        <div field="nickName" width="80" headerAlign="center" allowSort="true" >用户昵称</div>
        <div field="gender"  width="70" align="center" headerAlign="center" renderer="onGenderRenderer" allowSort="true" >用户iocn</div>
        <div field="qrCode" width="70" align="center" headerAlign="center" renderer="onGenderRenderer" allowSort="true" >用户二维码</div>
        <div field="live_authority" renderer="onLiveRenderer" align="center" width="60" headerAlign="center" allowSort="true">直播权限</div>
        <div field="sex" width="40"  align="center" headerAlign="center" allowSort="true">性别</div>
        <div field="uid" align="center" width="60" headerAlign="center" allowSort="true">部落id</div>
        <div field="signature" align="left" width="100" headerAlign="center" allowSort="true">个性签名</div>
        <div field="mobilePhoneNumber" align="center" headerAlign="center" width="70" allowSort="true" >电话号码</div>
        <div field="phoneRegVerify" align="center" headerAlign="center" width="70" allowSort="true" renderer="onPhoneRenderer">手机验证</div>
        <div field="status" align="center" headerAlign="center" width="70" allowSort="true"  renderer="onLoginRenderer">账号状态</div>
        <div field="createAt" width="100"  align="center" headerAlign="center" allowSort="true">创建日期</div>
        <div field="updatedAt" width="100"  align="center" headerAlign="center" allowSort="true">更新日期</div>
        <div field="username" width="120" headerAlign="center" allowSort="true">用户名称</div>
    </div>
</div>
</body>
<script type="text/javascript">
    var flag = 1;
    mini.parse();
    var grid = mini.get("datagrid1");
    grid.load();
    grid.on("drawcell", function (e) {
        var  value = e.value;
        column = e.column;
        //将性别文本替换成图片
        if (column.field == "gender") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImg()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
        if (column.field == "qrCode") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImgCode()" src="' + value +'" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImgCode()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
    });

    function search() {
        var nickName = mini.get("nickName").getValue();
        var userOId = mini.get("userOId").getValue();
        grid.load({
            nickName: nickName,
            userOId:userOId,
        });
    }
    function searchObjectId() {
        var objectId = document.getElementById("objectId").value;
        grid.load({objectId:objectId})
    }
    function searchMobilePhoneNumber() {
        var mobilePhoneNumber = document.getElementById("mobilePhoneNumber").value;
        grid.load({mobilePhoneNumber:mobilePhoneNumber})
    }
    $("#nickName,#objectId,#mobilePhoneNumber").bind("keydown", function (e) {
        if (e.keyCode == 13) {
            search();
        }
    });

    function onGenderRenderer() {
        var inputText = '<input id="id1"  required="true" value="1" class="mini-textbox" vtype="float" />';
        return inputText;
//        var image='<img src="http://img2.imgtn.bdimg.com/it/u=320009444,2072114424&fm=26&gp=0.jpg"  alt="上海鲜花港 - 郁金香"  style="width: 80px;height: 20px"/>';
//        return image;
    }
    // /////////////////////////////////////////////
    var Genders = [{ id: 1, text: '男' }, { id: 2, text: '女'}];
    function onGenderRenderer(e) {
        for (var i = 0, l = Genders.length; i < l; i++) {
            var g = Genders[i];
            if (g.id == e.value) return g.text;
        }
        return "";
    }

    function bigImg() {
        var row = grid.getSelected();
        if (row) {
            if(flag==1) {
                var path = row.gender;
                $("#imgId").attr('src', path);
                $("#outImg").css('display','block');
            }
        }
    }
    function bigImgCode() {
        var row = grid.getSelected();
        if (row) {
            if(flag==1) {
                var path = row.qrCode;
                $("#imgId").attr('src', path);
                $("#outImg").css('display','block');
            }
        }
    }
    function smallImg() {
        $("#outImg").css('display','none');
    }
    function add() {
        mini.open({
            url: "/editor/admin/userAdd",
            title: "选择列表",
            width: 700,
            height: 450,
            ondestroy: function (action) {
                //if (action == "close") return false;
                if (action == "ok") {
                    grid.load();
                }else if(action=="cancel"){
                    grid.load();
                }
            }
        });
    }
    function remove() {
        var row = grid.getSelected();
        if (row) {
            $.ajax({
                url: "/getdata/allow/adminLogin",
                type: 'post',
                data: {
                    objectId:row.objectId,
                    status:0
                },
                success: function (result) {
                    if (result == 0){
                        grid.load();
                    } else if (result == 1) {
                        grid.load();
                    }
                },
                error: function (error) {
                    console.log(error)
                }
            });
        }else{
            alert("请选中一条记录")
        }
    }

    function onBirthdayRenderer(e) {
        var value = e.value;
        if (value) return mini.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
        return "";
    }
    function onLiveRenderer(e) {
        var value = e.value;
        if (value==true||value==1) return (value, '可以直播');
        return "不能直播";
    }
    function onPhoneRenderer(e) {
        var value = e.value;
        if (value==true||value==1) return (value, '通过验证');
        return "未验证";
    }
    function onLoginRenderer(e) {
        var value = e.value;
        if (value==1) {
            return (value, '正常')
        }else if(value==0) {
            return (value, '删除');
        }

    }
</script>
</html>